package com.umakr.demo.controller;

import com.umakr.demo.model.Kecheng;
import com.umakr.demo.model.Student;
import com.umakr.demo.model.StudentKecheng;
import com.umakr.demo.service.KechengService;
import com.umakr.demo.service.StudentKechengService;
import com.umakr.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangliu on 2017/8/22.
 */
@Controller
@RequestMapping("/StudentKechengController")
public class StuentKechengController {



    @Autowired
    StudentKechengService studentKechengService;

    @Autowired
    StudentService studentService;

    @Autowired
    KechengService kechengService;

    @RequestMapping("/showStudentKecheng")
    public String showTeacherKecheng(){
        return "StudentManage/studentkecheng";
    }

    @RequestMapping("/studentData")
    @ResponseBody
    public List studentData(){
        List<Student> list = studentService.showStudent();
        return list;
     }


    @RequestMapping("/kechengDate")
    @ResponseBody
    public List kechengData(){
        List<Kecheng> list = kechengService.showAll();
        return  list;
    }

    @RequestMapping("/studentShowKecheng")
    @ResponseBody
    public List studentShowKecheng(Long sid){
        List<Kecheng> list = studentKechengService.studentShowKecheng(sid);
        return list;
    }

    @RequestMapping("/allSelectedKecheng")
    @ResponseBody
    public void allSelectedKecheng(Long sid,@RequestParam(value = "str[]",required = false) String[] str){
//        全部删除
        studentKechengService.deleteAll(sid);
        for (int i =0;i<str.length;i++){
            StudentKecheng studentKecheng = new StudentKecheng(sid,(Long.parseLong(str[i])));
            //执行添加
            System.out.println(studentKecheng.getSid());
            studentKechengService.addAll(studentKecheng);
        }
    }


}
